home *** CD-ROM | disk | FTP | other *** search
/ .net 2002 March / DotNetMagazine-Issue107-Coverdisc-NET107-02-03-PCMac.bin / pc / PC Software / free_browsing / DavesQckSearchDbar3-14 / dqsd.exe / searches / mq.xml < prev    next >
Text File  |  2002-09-06  |  4KB  |  111 lines

  1. <search function="mq">
  2.   <name>Mapquest Maps</name>
  3.   <description>
  4.     Find maps of United States locations.<br/>
  5.     <div class="helpboxDescLabels">Example:</div>
  6.     <table class="helpboxDescTable">
  7.           <tr><td>mq 1400 Constitution Ave NE, Washington DC</td></tr>
  8.       </table>
  9.   </description>
  10.   <category>People and Places</category>
  11.   <link>http://www.mapquest.com/</link>
  12.   
  13.   <form name="mqf"
  14.         action="http://www.mapquest.com/maps/map.adp" 
  15.         method="get">
  16.     <input type="hidden" name="country" value="US"/>
  17.     <input type="hidden" name="address"/>
  18.     <input type="hidden" name="city"/>
  19.     <input type="hidden" name="state"/>
  20.     <input type="hidden" name="zipcode"/>
  21.   </form>
  22.   
  23.   <script><![CDATA[
  24.     function mq(q)
  25.     {
  26.       if( nullArgs("mq",q) )
  27.         return false;
  28.       else
  29.       {
  30.         // What follows is a fairly "ergonomic" parser for US addresses that I slapped together.
  31.         // It recognizes states, zip+4 codes, and common street enders such as st, ave, and rd.
  32.         // It doesn't yet recognize apartment numbers.
  33.  
  34.         var address = "";
  35.         var city = "";
  36.         var state = "";
  37.         var zipcode = "";
  38.  
  39.         // trim trailing zip
  40.         var res = q.match(/(\d{5}(-\d{4})?)[\s\.,;]*$/);
  41.         if (res && res[1])
  42.         {
  43.           zipcode = res[1];
  44.           q = q.substring(0, res.index);
  45.         }
  46.  
  47.         // trim trailing state code
  48.         res = q.match(/\b(AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY)[\s\.,;]*$/i);
  49.         if (res && res[1])
  50.         {
  51.           state = res[1];
  52.           q = q.substring(0, res.index);
  53.         }
  54.  
  55.         // detect leading ### w w w st
  56.         res = q.match(/^\s*(\d+(\s+\w+)+\s+(st|ave|rd|ln|dr|blvd|cir|ct|pkwy|pl|way|aly|pk|sq|ter|plz))[\s\.,;]*(.*)$/i);
  57.         if (res && res[1])
  58.         {
  59.           address = res[1];
  60.           city = res[4];
  61.         }
  62.  
  63.         // detect trailing comma or semicolon; prefer this way of finding city
  64.         res = q.match(/[\.,;]\s*([^\d][^,;]+)[\s\.,;]*$/i);
  65.         if (res && res[1])
  66.         {
  67.           city = res[1];
  68.           address = q.substring(0, res.index);
  69.         }
  70.  
  71.         // last resorts: we really want a city
  72.         if (city == "")
  73.         {
  74.           // drop requirement for street number and precise abbreviation and look for street
  75.           res = q.match(/^\s*((\w+\s+)+(st|ave|rd|ln|dr|blvd|cir|ct|pkwy|pl|way|aly|pk|sq|ter|plz|street|avenue|road|lane|drive|boulevard|circle|court|parkway|place|loop|alley|park|square|terrace|plaza|mall))[\s\.,;]*(.*)$/i);
  76.           if (res && res[1])
  77.           {
  78.             address = res[1];
  79.             city = res[4];
  80.           }
  81.           // has a number: city is last word
  82.           else if (q.match(/^\s*\d/))
  83.           {
  84.             res = q.match(/(\w+)[\s\.,;]*$/);
  85.             city = res[1];
  86.             address = q.substring(0, res.index);
  87.           }
  88.           // otherwise, looks like it doesn't have a street; city is whole thing
  89.           else
  90.           {
  91.             city = q;
  92.             address = "";
  93.           }
  94.         }
  95.         
  96.         document.mqf.address.value=address;
  97.         document.mqf.city.value   =city;
  98.         document.mqf.state.value  =state.toUpperCase();
  99.         document.mqf.zipcode.value=zipcode;
  100.         submitForm(mqf);
  101.       }
  102.     }
  103.   ]]></script>
  104.  
  105.   <copyright>
  106.     Copyright (c) 2002 David Bau
  107.     Distributed under the terms of the
  108.     GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
  109.   </copyright>
  110. </search>
  111.